package com.example.mobile2121606109ycg0524homework1;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class StaffRViewAdapter extends RecyclerView.Adapter<StaffRViewAdapter.ViewHolder> {
    private List<Staff> list;

    public StaffRViewAdapter(List<Staff> list) {
        this.list = list;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvItemName,tvItemSkill,tvItemSalary;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvItemName = itemView.findViewById(R.id.tvItemName);
            tvItemSkill = itemView.findViewById(R.id.tvItemSkill);
            tvItemSalary = itemView.findViewById(R.id.tvItemSalary);
        }
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_main_staff,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull StaffRViewAdapter.ViewHolder holder, int position) {
        Staff staff = list.get(position);
        holder.tvItemName.setText(staff.getName());
        holder.tvItemSkill.setText(staff.getSkill());
        holder.tvItemSalary.setText(staff.getSalary());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
